const loadCss = (path) => {
  const head = document.querySelectorAll("head")[0]
  const link = document.createElement("link")
  link.id = "9999999"
  link.href = path
  link.rel = "stylesheet"
  link.type = "text/css"
  head.append(link)
}
export default function changeTheme(themeValue) {
  const path = process.env.NODE_ENV === "production" ?  window.env.staticPath : ""
  const itemPath =  `${path}/theme/${themeValue}/index.css?ver=${Date.now()}`
  loadCss(itemPath)
}

export function setTheme () {
  const { theme } = window.env
  if (!theme) return 
  changeTheme(theme)
  const body = document.querySelectorAll("body")[0]
  body.style.setProperty("--color-primary", `#${theme}`)
  body.style.setProperty("--color-primary--hover", `${theme === "c81930" ? "#FCF2F2" : "#eef1ff"}`)
  body.className = `t-${theme}`
}